package com.navinfo.opentsp.platform.computing.service.huashen;

import com.navinfo.opentsp.platform.computing.anno.RoutingProtocol;
import com.navinfo.opentsp.platform.computing.enums.ProtocolEnum;
import com.navinfo.opentsp.platform.computing.enums.YardEnum;
import com.navinfo.opentsp.platform.computing.service.IProtocolParseService;
import com.navinfo.opentsp.platform.location.protocol.common.LCTerminalStatisticData;
import org.apache.flume.Event;

@RoutingProtocol(yard= YardEnum.HUASHEN, protocolType = ProtocolEnum.STATISTICS_DATA)
public class StatisticsDataHuaShenService implements IProtocolParseService {


    @Override
    public String parseProtocol(Event event) {
        try{
            LCTerminalStatisticData.StatisticData statisticData = LCTerminalStatisticData.StatisticData.parseFrom(event.getBody());
            StringBuilder locationStr = new StringBuilder(5000);
            locationStr
                    .append(statisticData.getTerminalId()).append(splitStr)
                    .append(statisticData.getSerialNumber()).append(splitStr)
                    .append(statisticData.getRetransmissionPackets()).append(splitStr)
                    .append(statisticData.getReceiveDate()).append(splitStr)
                    .append(statisticData.getVersion()).append(splitStr)
                    .append(statisticData.getRouteStopFlag()).append(splitStr)
                    .append(statisticData.getCrossDaysFlag()).append(splitStr)
                    .append(statisticData.getTime()).append(splitStr)
                    .append(statisticData.getLatitude()).append(splitStr)
                    .append(statisticData.getLongitude()).append(splitStr)
                    .append(statisticData.getOriginalLat()).append(splitStr)
                    .append(statisticData.getOriginalLng()).append(splitStr)
                    .append(statisticData.getHeight()).append(splitStr)
                    .append(statisticData.getDirection()).append(splitStr)
                    .append(statisticData.getDepotLogo()).append(splitStr)
                    .append(statisticData.getProtocolVersion()).append(splitStr)
                    .append(statisticData.getRouteStartTime()).append(splitStr)
                    .append(statisticData.getRouteEndTime()).append(splitStr)
                    .append(statisticData.getGpsSpeedStatisticsMileage()).append(splitStr)
                    .append(statisticData.getMeterSpeedIntegralMileage()).append(splitStr)
                    .append(statisticData.getSpeedStatisticsLifeMileage()).append(splitStr)
                    .append(statisticData.getVehicleTotalMileage()).append(splitStr)
                    .append(statisticData.getVehicleEstimatedLoad()).append(splitStr)
                    .append(statisticData.getRouteIntegralFuelConsumption()).append(splitStr)
                    .append(statisticData.getIntegralFuelConsumption()).append(splitStr)
                    .append(statisticData.getVehicleTotalFuelConsumption()).append(splitStr)
                    .append(statisticData.getAverageFuelConsumption()).append(splitStr)
                    .append(statisticData.getOverSpeedTimes()).append(splitStr)
                    .append(statisticData.getOverSpeedDistance()).append(splitStr)
                    .append(statisticData.getOverSpeedFuelConsumption()).append(splitStr)
                    .append(statisticData.getBrakeNumber()).append(splitStr)
                    .append(statisticData.getCumulativeMileage()).append(splitStr)
                    .append(statisticData.getBrakingTime()).append(splitStr)
                    .append(statisticData.getSharpDownSpeedTime()).append(splitStr)
                    .append(statisticData.getSharpDownSpeedMileage()).append(splitStr)
                    .append(statisticData.getSharpDownSpeedFrequency()).append(splitStr)
                    .append(statisticData.getSharpUpSpeedTime()).append(splitStr)
                    .append(statisticData.getSharpUpSpeedMileage()).append(splitStr)
                    .append(statisticData.getSharpUpSpeedFrequency()).append(splitStr)
                    .append(statisticData.getSharpUpSpeedFuelConsumption()).append(splitStr)
                    .append(statisticData.getSharpCurveMileage()).append(splitStr)
                    .append(statisticData.getSharpCurveFrequency()).append(splitStr)
                    .append(statisticData.getFatigueDrivingFrequency());

            return locationStr.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


}
